package org.mogu;


import org.mogu.control.model.IMUser;
import org.mogu.db.DBhelper;
import org.mogu.service.GetSyncUrl;
import org.mogu.service.InfoSync;
import org.mogu.staticvalue.Convert;
import org.mogu.tools.UrlSync;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.view.Window;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;


/*
 * 设置管理界面
 * @author androidSource@139.com
 * */
public class SettingManagerActivity extends Activity 
		implements View.OnClickListener{

	/*
	 * 相关变量定义
	 * */
	public static SettingManagerActivity instance = null;
	
//	public static SetStatusListAdapter mSetStatusListAdapter = null;
	
//	private RelativeLayout mMyStatusItem = null;
	
	 /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);//启用窗体的扩展特性,此处请求为没有标题的activity
//        setContentView(R.layout.setting_manager);//设置当前使用的布局文件
        instance = this;
        
        
//        mMyStatusItem = (RelativeLayout)findViewById(R.id.myStatusItem);
//        mMyStatusItem.setOnClickListener(this);
        
        
    }
    
    @Override
    public void onClick(View v){
//    	switch(v.getId()){
//	    	case R.id.myStatusItem:
//	    		SetStatuDialog(SettingManagerActivity.this);
//	    		break;
//    	}
    }
	
//    public static void SetStatuDialog(Context paramContext){
//    	 ListView mListView = new ListView(paramContext);	
//    	 mListView.setItemsCanFocus(true);
//    	 mListView.setCacheColorHint(0);
//    	 
//    	 ArrayList localArrayList = new ArrayList();
//    	 String []statusArray = paramContext.getResources().getStringArray(R.array.status_strs);
//    	 for(int i = 0; i < statusArray.length; i++){
//    		 //在线
//    		 if(i == 0){
//    			 setList(localArrayList,R.drawable.status_online,statusArray[0],true);
//    		 }
//    		 //隐身
//    		 else if(i == 1){
//    			 setList(localArrayList,R.drawable.status_invisible,statusArray[1],false);
//    		 }
//    		 //离开
//    		 else if(i == 2){
//    			 setList(localArrayList,R.drawable.status_away,statusArray[2],false);
//    		 }
//    		 //离线
//    		 else if(i == 3){
//    			 setList(localArrayList,R.drawable.status_offline,statusArray[3],false);
//    		 }
//    	 }
//    	 
//         
//    	 mSetStatusListAdapter = new SetStatusListAdapter(paramContext, localArrayList);
//    	 mListView.setAdapter(null);
//         mListView.removeAllViewsInLayout();
//         mListView.setAdapter(mSetStatusListAdapter);
//         
//         QqDialog setStatusDialog  = new QqDialog(paramContext,mListView,true);
//         setStatusDialog.show();
//    }     
    
//    public static void ChangeAlertNameDialog(Context paramContext){
//    	EditText eAlertName = new EditText(paramContext);
//    	LinearLayout.LayoutParams eLayoutParam = new  LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT
//    				,LinearLayout.LayoutParams.WRAP_CONTENT);
//    	eAlertName.setPadding(10, 10, 10, 10);
//    	eAlertName.setLayoutParams(eLayoutParam);
//    	
//    	
//    	 QqDialog setStatusDialog  = new QqDialog(paramContext,eAlertName,true);
//         setStatusDialog.show();
//    }
    
    public static IMUser imUser=null;
    private static Handler mMainHandler;
    
    public static void DeleteContactItem(Context paramContext,IMUser imuser,Handler mainHandler){
    	context=paramContext;
    	imUser=imuser;
    	mMainHandler=mainHandler;
    	TextView eDeleteW = new TextView(paramContext);
    	LinearLayout.LayoutParams eLayoutParam = new  LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT
    				,LinearLayout.LayoutParams.WRAP_CONTENT);
    	eDeleteW.setPadding(10, 10, 10, 10);
    	eDeleteW.setText("确定删除该好友么？");
    	eDeleteW.setTextColor(Color.WHITE);
    	eDeleteW.setTextSize(18);
    	eDeleteW.setLayoutParams(eLayoutParam);
    	
    	AlertDialog.Builder builder;
    	builder = new  AlertDialog.Builder(paramContext);
    	AlertDialog myDialog  = builder.create();  
    	myDialog.setMessage(eDeleteW.getText());
    	myDialog.setTitle("提示");
    	myDialog.setCancelable(false);
    	
         myDialog.setButton("取消", new DialogInterface.OnClickListener() {

 			@Override
 			public void onClick(DialogInterface dialog, int which) {
 				mMainHandler=null;
 				dialog.dismiss();

 			}
 		});
 		myDialog.setButton2("删除",
 				new DialogInterface.OnClickListener() {

 					@Override
 					public void onClick(DialogInterface dialog, int which) {
 						dialog.dismiss();
 						UrlSync urlSync=new UrlSync();
 						urlSync.setUri(GetSyncUrl.getAppUrlByCode(imUser.getMaincode())+"/DelFriend");
 						urlSync.setResultType("33");
 						urlSync.setModth(UrlSync.GET);
 						urlSync.setNotice(false);
 						urlSync.setUrlparam("&Friend="+imUser.getUname());
 						urlSync.setMaincode(imUser.getMaincode());
 						urlSync.setCode(imUser.getCode());
 						urlSync.setToastContentFa("删除好友[ "+imUser.getUnicename()+" ]失败。");
 						urlSync.setToastContentSu("删除好友[ "+imUser.getUnicename()+" ]成功。");
 						urlSync.setImUser(imUser);
 						urlSync.setHandler(mMainHandler);
 						mMainHandler=null;
 						synchronized (Convert.class) {
 							Convert.syncList.add(0,urlSync);
 						}
 					}
 				});
 		myDialog.show();
    }
    public static void DeleteFriendItem(Context paramContext,IMUser imuser,Handler mainHandler){
    	context=paramContext;
    	imUser=imuser;
    	mMainHandler=mainHandler;
    	TextView eDeleteW = new TextView(paramContext);
    	LinearLayout.LayoutParams eLayoutParam = new  LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT
    			,LinearLayout.LayoutParams.WRAP_CONTENT);
    	eDeleteW.setPadding(10, 10, 10, 10);
    	eDeleteW.setText("确定删除该联系人么？");
    	eDeleteW.setTextColor(Color.WHITE);
    	eDeleteW.setTextSize(18);
    	eDeleteW.setLayoutParams(eLayoutParam);
    	
    	
    	AlertDialog.Builder builder;
    	builder = new  AlertDialog.Builder(paramContext);
    	AlertDialog myDialog  = builder.create();  
    	myDialog.setMessage(eDeleteW.getText());
    	myDialog.setTitle("提示");
    	myDialog.setCancelable(false);
    	
    	myDialog.setButton("取消", new DialogInterface.OnClickListener() {
    		
    		@Override
    		public void onClick(DialogInterface dialog, int which) {
    			mMainHandler=null;
    			dialog.dismiss();
    			
    		}
    	});
    	myDialog.setButton2("删除",
    			new DialogInterface.OnClickListener() {
    		
    		@Override
    		public void onClick(DialogInterface dialog, int which) {
    			dialog.dismiss();
    			UrlSync urlSync=new UrlSync();
    			urlSync.setUri(GetSyncUrl.getAppUrlByCode(imUser.getMaincode())+"/DelFriend");
    			urlSync.setResultType("36");
    			urlSync.setModth(UrlSync.GET);
    			urlSync.setNotice(false);
    			urlSync.setUrlparam("&Friend="+imUser.getUname());
    			urlSync.setMaincode(imUser.getMaincode());
    			urlSync.setCode(imUser.getCode());
    			urlSync.setToast(false);
    			urlSync.setToastContentFa("删除好友[ "+imUser.getUnicename()+" ]失败。");
    			urlSync.setToastContentSu("删除好友[ "+imUser.getUnicename()+" ]成功。");
    			urlSync.setImUser(imUser);
    			urlSync.setHandler(mMainHandler);
    			mMainHandler=null;
    			synchronized (Convert.class) {
    				Convert.syncList.add(0,urlSync);
    			}
    			String[] where={imUser.getCode(),imUser.getCode(),Convert.uname};
					synchronized (InfoSync.class) {
						DBhelper.getDBHelper(context).getWritableDatabase().delete("content", "(father=? or code=?) and username=?", where);
//						Toast.makeText(context, "聊天记录删除成功。", 4000).show();
					}
    		}
    	});
    	myDialog.show();
    }
    public static void AddContactItem(Context paramContext,IMUser imuser,Handler mainHandler){
    	context=paramContext;
    	imUser=imuser;
    	mMainHandler=mainHandler;
    	TextView eDeleteW = new TextView(paramContext);
    	LinearLayout.LayoutParams eLayoutParam = new  LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT
    			,LinearLayout.LayoutParams.WRAP_CONTENT);
    	eDeleteW.setPadding(10, 10, 10, 10);
    	eDeleteW.setText("确定加为好友么？");
    	eDeleteW.setTextColor(Color.WHITE);
    	eDeleteW.setTextSize(18);
    	eDeleteW.setLayoutParams(eLayoutParam);
    	
    	
    	AlertDialog.Builder builder;
    	builder = new  AlertDialog.Builder(paramContext);
    	AlertDialog myDialog  = builder.create();  
    	myDialog.setMessage(eDeleteW.getText());
    	myDialog.setTitle("提示");
    	myDialog.setCancelable(false);
    	
    	myDialog.setButton("取消", new DialogInterface.OnClickListener() {
    		
    		@Override
    		public void onClick(DialogInterface dialog, int which) {
    			mMainHandler=null;
    			dialog.dismiss();
    			
    		}
    	});
    	myDialog.setButton2("加为好友",
    			new DialogInterface.OnClickListener() {
    		
    		@Override
    		public void onClick(DialogInterface dialog, int which) {
    			dialog.dismiss();
    			UrlSync urlSync=new UrlSync();
    			urlSync.setUri(GetSyncUrl.getAppUrlByCode(imUser.getMaincode())+"/AddFriend");
    			urlSync.setResultType("34");
    			urlSync.setModth(UrlSync.GET);
    			urlSync.setNotice(false);
    			urlSync.setUrlparam("&Friend="+imUser.getUname());
    			urlSync.setMaincode(imUser.getMaincode());
    			urlSync.setCode(imUser.getCode());
    			urlSync.setToastContentFa("添加好友[ "+imUser.getUnicename()+" ]失败。");
    			urlSync.setToastContentSu("添加好友[ "+imUser.getUnicename()+" ]成功。");
    			urlSync.setImUser(imUser);
    			urlSync.setHandler(mMainHandler);
    			mMainHandler=null;
    			synchronized (Convert.class) {
    				Convert.syncList.add(0,urlSync);
    			}
    		}
    	});
    	myDialog.show();
    }
    
    private static String father=null;
    private static Context context=null;
    
    public static void DeleteHistoryItem(Context paramContext,String code){
    	context=paramContext;
    	father=code;
    	TextView eDeleteW = new TextView(paramContext);
    	LinearLayout.LayoutParams eLayoutParam = new  LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT
    				,LinearLayout.LayoutParams.WRAP_CONTENT);
    	eDeleteW.setPadding(10, 10, 10, 10);
    	eDeleteW.setText("确定删除该好友的聊天记录？");
    	eDeleteW.setTextColor(Color.WHITE);
    	eDeleteW.setTextSize(18);
    	eDeleteW.setLayoutParams(eLayoutParam);
    	
    	
    	AlertDialog.Builder builder;
    	builder = new  AlertDialog.Builder(paramContext);
    	AlertDialog myDialog  = builder.create();  
    	myDialog.setMessage(eDeleteW.getText());
    	myDialog.setTitle("提示");
    	myDialog.setCancelable(false);
         myDialog.setButton("取消", new DialogInterface.OnClickListener() {

 			@Override
 			public void onClick(DialogInterface dialog, int which) {
 				dialog.dismiss();

 			}
 		});
 		myDialog.setButton2("删除",
 				new DialogInterface.OnClickListener() {

 					@Override
 					public void onClick(DialogInterface dialog, int which) {
 						dialog.dismiss();
 						String[] where={father,Convert.uname};
 						synchronized (InfoSync.class) {
 							DBhelper.getDBHelper(context).getWritableDatabase().delete("content", "father=? and username=?", where);
 							Toast.makeText(context, "聊天记录删除成功。", 4000).show();
 						}
 					}
 				});
 		myDialog.show();
         
    }
    
//    public static void WranDialog(Context paramContext, String message
//    		,boolean doubleButton){
//    	TextView eDeleteW = new TextView(paramContext);
//    	LinearLayout.LayoutParams eLayoutParam = new  LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT
//    				,LinearLayout.LayoutParams.WRAP_CONTENT);
//    	eDeleteW.setPadding(10, 10, 10, 10);
//    	eDeleteW.setTextColor(Color.WHITE);
//    	eDeleteW.setTextSize(18);
//    	eDeleteW.setLayoutParams(eLayoutParam);
//    	
//    	eDeleteW.setText(message);
//    	
//    	 QqDialog setStatusDialog  = new QqDialog(paramContext,eDeleteW,doubleButton);
//         setStatusDialog.show();
//    }
    
//    private static void setList(List paramList, int paramInt, String paramString,
//    			boolean paramBoolean){
//      HashMap localHashMap = new HashMap();
//      Integer localInteger = Integer.valueOf(paramInt);
//      Object localObject1 = localHashMap.put("img", localInteger);
//      Object localObject2 = localHashMap.put("name", paramString);
//      Boolean localBoolean = Boolean.valueOf(paramBoolean);
//      Object localObject3 = localHashMap.put("isChecked", localBoolean);
//      
//      boolean bool = paramList.add(localHashMap);
//    }
  
}
